<?
print "<div class='resizeXY' id='dmessagedetail' style='overflow:auto;display:none' ></div>"; 
print "<div  id='dmessagelist'>";

$patterns = array();
while (list ($a,$b) = each ($result["articles"])) 
{ 
	if ($lc > RESULT_PAGE_SIZE)
	{
		break;
	} 
	else if ($start_id=="" || $b->nntp_message_id > $start_id)
	{   
	
		while (list ($r,$g) = each ($patterns)) 
		{
		    $pat_test = preg_match ($r, $b->subject, $tmp);
			if ($pat_test)
			{ 
				$patterns[$r][count($patterns[$r])] = $b;
				break;
			}
		}
		
		reset ($patterns);

		$pattern     = str_replace ("[", ".+", $b->subject);
		$pattern     = str_replace ("]", ".+", $pattern);
		$pattern     = str_replace ("(", ".+", $pattern);
		$pattern     = str_replace (")", ".+", $pattern);
		$pattern     = str_replace ("*", "\\*", $pattern);
		$pattern     = str_replace ("=", "\\=", $pattern);
		$pattern     = str_replace ("/", "\\/", $pattern);
		$pattern     = preg_replace ("/(\d+)/", "(\d+)", $pattern);  
		$pattern     = "/". trim($pattern)."/i";
		 
		if (array_key_exists($pattern, $patterns))
		{
		    
		}		
		else
		{
		    $patterns[$pattern] = array($b);
		} 
	} 
}

print "<!-- ";
#  print_r ($patterns);
print " -->";

reset ($result["articles"]);

if ($pp_v=="thumb")
{



	$thumbnail_table = "<div class='resizeXY' style='overflow:auto' >
		  <table id='newstable' bgcolor='white' cellpadding=2  cellspacing=0 ><tr>";
	$nonpics = array ();
	while (list ($a, $b) = each ($patterns)) 
	{
	    $image_test = preg_match("/\.(jpeg|jpg|gif|png)/i",$b[0]->subject,$image_map);
		if ($image_test)
		{
		    $lc ++; 
			
			$arr = array (
			              '/File(.*\.\w{3})/i',
						  '/"(.*)"/',
						  '/(\S+\.\w{3})/');
			$caption = $b[0]->subject;
			foreach ($arr as $r)
			{
			    if (preg_match($r,$b[0]->subject,$ret))
				{
				    $caption = $ret[1];
				}
			}
			$caption = str_replace("\"", "", $caption);
			$caption = chop_str($caption, 30);
			$tmp=array();
			for ($cnt=0;$cnt<count($b);$cnt++)
			{
			     $tmp[]=$b[$cnt]->nntp_message_id;
				 if ($cnt>2)
				 {
				    break;
				 }
			}
			$tmp=implode (',', $tmp);
			
						 # onmouseover='cycle_on(\"img_".$b[0]->nntp_message_id."\", \"".$tmp."\")'
						 # onmouseout ='cycle_off(\"img_".$b[0]->nntp_message_id."\")'
			$thumbnail_table .= "
			         <td valign=top align=center nowrap>
					     <div style='border:solid 1px silver;width:180;height:180;overflow:hidden'
						  ><a target=_blank href='newsgroups.php?message_id=" 
						  . $b[0]->nntp_message_id . "&art_group=" 
						  . $group_name . "'
					     ><img 
						  id='img_".$b[0]->nntp_message_id."'
						  border='0'
					      alt='" . htmlentities($b[0]->subject) . "\n" . htmlentities($b[0]->from["name"]) . "' 
						  onload='desktop_background_resize()' 
						  src='newsgroups.php?message_id=".$b[0]->nntp_message_id."&art_group=".$group_name."&pp_w=180'
						 ></a></div>
						<div align=left>
						<a " . (count($b)>1?"href='javascript:cycle_on(\"img_".$b[0]->nntp_message_id."\", \"".$tmp."\")'":"") . "
						 ><img border='0' 
						       id='imp_".$b[0]->nntp_message_id."' 
							   src='images/" . (count($b)>1?"pw":"pd") . ".png' 
							   align='absmiddle'></a>
						 File: <a target=_blank href='newsgroups.php?message_id=" 
						  . $b[0]->nntp_message_id . "&art_group=" 
						  . $group_name . "&a=slide'
					     >" . htmlentities($caption) ."</a> <br>
					   &lt;<a href=\"" 
					      . htmlentities($b[0]->from["email"]) . "\">" 
						  . htmlentities($b[0]->from["name"]) . "</a>&gt;<br> 
					    <a target=_blank href='newsgroups.php?message_id=" 
						  . $b[0]->nntp_message_id . "&art_group=" 
						  . $group_name . "&a=slide'
					     >" . count($b) . "</a> article".(count($b)==1?"":"s")."
					     </div>
					 </td>";
			if ($lc%5==0)
			{
				$thumbnail_table.="</tr><tr>";
			}					 
		} 
		else
		{
		     $nonpics[] = $b;
		}
	}
	
	while (list ($a,$b) = each ($nonpics)) 
	{
		$cnt=0;
		$thumbnail_table.="</tr><tr><td colspan='5'><a target=_blank href='newsgroups.php?message_id=" 
						  . $b[$cnt]->nntp_message_id . "&art_group=" 
						  . $group_name . "&a=slide'
					   >" . htmlentities($b[$cnt]->subject) ."</a> (".count($b)." articles)</td>"; 
		for ($cnt=1;$cnt<count($b);$cnt++)
		{ 
			$thumbnail_table.="</tr><tr style='display:none'>
			               <td 
			                   colspan='5'><a target=_blank href='newsgroups.php?message_id=" 
							  . $b[$cnt]->nntp_message_id . "&art_group=" 
							  . $group_name . "&a=slide'
						   >" . htmlentities($b[$cnt]->subject) ."</a></td>"; 
			$thumbnail_table.=""; 
		}
	}
	/*
	while (list ($a,$b) = each ($result["articles"])) 
	{ 
		if ($lc >= 100)
		{
			break;
		} 
		else if ($start_id=="" || $b->nntp_message_id > $start_id)
		{   
			$image_test = preg_match("/(\w+).*(jpeg|jpg|gif|png)/i",$b->subject,$image_map);
			if ($image_test)
			{
 			
				$lc ++; 
				$thumbnail_table.= "<td><img alt='". htmlentities($b->subject) ."' onload='desktop_background_resize()' src='newsgroups.php?message_id=".$b->nntp_message_id."&art_group=".$group_name."&pp_w=180'></td>";
				if ($lc%5==0)
				{
					$thumbnail_table.="</tr><tr>";
				}
			} 
		}
	}*/
	
	$thumbnail_table.="</tr></table></div>";
	
	
}


reset ($result["articles"]);

if ($pp_v=="")
{
	$t = "<div class='resizeXY' style='overflow:auto' >
		  <table width='100%' id='newstable' bgcolor='white'  cellpadding=2  cellspacing=0 > 
			<tr style='border-right:solid 1px silver;'>  
				<td bgcolor='#E0E0E0' class='header'>lines</td> 
				<td bgcolor='#E0E0E0' class='header'>subject</td> ";
				
	if ($search_param=="")
	{
		$t .= "<td bgcolor='#E0E0E0' class='header'>from</td> 
		<td bgcolor='#E0E0E0' class='header'>size</td> 
		<td bgcolor='#E0E0E0' class='header'>age</td> 
		";
	}
	
	$t .= "<td bgcolor='#E0E0E0' width='100%' class='header'>&nbsp;</td></tr>"; 
	
	$multi = array(); 
	$masks = array(); 
	$sink  = ""; 
	$lc    = 0;
	$mask  = "";
	
		   
	while (list ($a,$b) = each ($result["articles"])) 
	{ 
		if ($lc > RESULT_PAGE_SIZE)
		{
			break;
		} 
		else if ($start_id=="" || $b->nntp_message_id > $start_id)
		{  
			$lc ++;
			$mink  = "newsgroups.php?art_group=" . $group_name . "&message_id=".$b->nntp_message_id.""; 
			 
			 
			$test_image = strpos (parse_MIME_header ($b->subject), "image");
			$test_text  = strpos (parse_MIME_header ($b->subject), "text/plain"); 
			
			if ($test_image===false && $test_text===false)
			{
				$jink  = "load_image(\"$mink\", " . $b->nntp_message_id . ", false)";  
			}
			else
			{
				$jink  = "load_image(\"$mink\", " . $b->nntp_message_id . ", true)"; 
			}
			
			
			if ($sink=="") 
			{ 
				$sink  = $jink; 
			}  
			
			$file_name_test = preg_match("/(\S*\.\w{3}.*)/", $b->subject, $tmp); 	
			if ($file_name_test)
			{
			   $caption = str_replace($tmp[1],"",$b->subject);
			   $display = $tmp[1];
			}
			else
			{
				$display = $b->subject;
			}
			
			$file_part_test = preg_match("/[(](\d+)\/(\d+)[)]/", $display, $tmp);
			if ($file_part_test) 
			{
			   $display = preg_replace("/[(](\d+)\/(\d+)[)]/", "<font color='black' style='font-weight:normal'>(\\1/\\2)</font>",$display); 
			   $rest    = substr($display,strpos($display,$tmp[0])+strlen($tmp[0]));
			   if ($rest!="")
			   {
				  $caption .= $rest;
				  $display = str_replace($rest,"",$display);
			   }
			}
			
			 $caption = preg_replace(array (
						   "/([[ ])+(\d+)( *\/ *)(\d+)([] ])+/",
						   "/[[](\d+) *- *(\d+)[]]/",
						   "/ *(\d+) *of *(\d+)/",
						   "/ *(\d+) *\/ *(\d+)\s*$/",
						   "/[([](\d+) *of *(\d+)[])]/" 
									   ) , "<font color='slateblue'>\\0</font>", $caption); 
			 
			
			$display = preg_replace("/\.(\w{3})\"*\W/","<font color='#FF0066'>\\0</font>", $display);
			$mpg_test = preg_match("/\.+(mpg|mpeg)[^\.]\W/", $b->subject, $mpg);
			$color="white";
			if ($mpg_test)
			{
				$color="#f0fff0";
			}
			$t .= "<tr id='tr" . $b->nntp_message_id . "' bgcolor='".$color."'>";  
			$t .= "<td class='row' align='right' nowrap>" . $b->line_count . "&nbsp;</td>"; 
			$t .= "<td class='row' nowrap>
				  <a style='font:8pt tahoma;color:#333333' href='javascript:$jink'>".$caption."</a>" . ($caption==""?"":"<br>") . "
				   <a title=\"". htmlentities($b->subject) . "\" class='navig' 
					  href='javascript:$jink'>"  .  $display . "</a></td>"; 
			if ($search_param=="")
			{
				$t .= "<td class='row' nowrap
						><a href=\"javascript:fb_edit('s','','fu','" . htmlentities( $b->from["name"] ) . "')\"
						>" .htmlentities( $b->from["name"] ) . "</a>&nbsp;</td>";
				$t .= "<td class='row' align=right nowrap>" . number_format( $b->byte_count/1000,2) . " Kb</td>"; 
				$t .= "<td class='row' nowrap>" . number_format((time() - $b->date)/86400,1). "d</td>"; 
			}
			else
			{
				$t .= "<td colspan='3' class='row'>&nbsp;</td>";
			}
			$t .= "<td class='row' width='100%' >&nbsp;"; 
			$t .= "</td></tr>"; 
			$last_id = $b->nntp_message_id; 
			print "<script language='javascript'>articles.push('" . $jink . "');</script>"; 
		}
	} 
	
	
	$t .= "</table></div>"; 
}
else
{
   $t=$thumbnail_table;
   $tablestyle="style='display:none'";
}																
																																														   
print ' 
<table> 
  <tr> 
	 <td valign="top" width="' . $ps . '"> 
		 <table width="' . $ps . '" cellspacing="1" cellpadding="1" bgcolor="#CCFFCC" '.$tablestyle.'> 
			<tr> 
				<td><img src="http://www.101stratford.com/pimp/?i=pu" align="absmiddle" >Article Details
				&nbsp;&nbsp;
				<input type="checkbox" onclick="fb_edit(\'a\', \'preview\')" ' . ($cookie_preview=="preview" ? "checked" : ""). '>Preview Images
				</td> 
			</tr> 
			<tr> 
				<td bgcolor="white"> 
				<table width="' . $ps . '" height="100%"> 
				   <tr> 
					   <td align="center"> 
						   <div id="dinfo" style="width:' . $ps . 'px;height:' . $ps . 'px;overflow:hidden;border:solid 1px silver">[No image loaded]</div>                                                                                                                                  
						   <div id=dmore></div> ';
						   
if ($cookie_preview=="preview") 
{
	print  '<a href="javascript:adv(-2)"><img border="0" src="images/back.bmp"></a> 
	&nbsp;&nbsp; 
	<a href="javascript:adv(0)"><img border="0" src="images/next.bmp"></a> 
	<br> ';
							   
	while ( list ($key, $val) = each ($thumbnail_sizes) )
	{
		if ($ps==$val)
		{
			print $key . ' | ';
		}
		else
		{
			print '<a href="javascript:fb_edit(\'ps\',' . $val . ')">' . $key . '</a> | ';
		}
	}
}
							
print '  </td> 
				   </tr> 
				</table>
				</td> 
			</tr> 
		 </table>  ';
				
print ' <!-- 
		 <table cellspacing="1" cellpadding="1" width="100%" bgcolor="#CCFFCC" > 
			<tr> 
				<td><img src="http://www.101stratford.com/pimp/?i=pu" align="absmiddle" >Page Details
				&nbsp;&nbsp;
				 
				</td> 
			</tr> 
			<tr> 
				<td bgcolor="white"> 
				 <table width="100%" height="100%"> 
				   <tr> 
					   <td><table> ';
					   
while ( list ($key, $val) = each ($multi) ) 
{  
   $m = "";
   foreach ($val as $v)
   {
      $m .= ($m==""?"":",") . $v->nntp_message_id;
   }
    print " <tr>
	      <td align='right'>" . count($val) . "</td>
		  <td><a href='newsgroups.php?a=mnzb&message_id=" . $m . "&art_group=" . $group_name . "'
							><img src='images/ZIP_sm.gif' border='0' align=absmiddle></a></td>
		  <td><a href='newsgroups.php?a=mnzb&message_id=" . $m . "&art_group=" . $group_name . "'
							>" . htmlentities( $val[0]->subject ) . "</a></td></tr>";
} 			 
print '  </table> </td> 
				   </tr> 
				</table>
				</td> 
			</tr> 
		 </table>  --> ';
				
print '
		 
	 </td> 
	 <td valign="top" width="100%">' . $t . '</td> 
  </tr> 
</table></div>'; 
																																																																																		 
if ($article_list === FALSE) 
{ 
	echo "<b>".$messages_ini["error"]["group_fail"].$_SESSION["newsgroup"]." </b><br>"; 
	echo $nntp->get_error_message()."<br>"; 
	exit; 
} 
?>